import java.io.ObjectOutputStream;
import java.net.Socket;

public class Client {
	public static void main(String[] args) throws Exception {
		Socket client = new Socket("127.0.0.1", 1234);
		ObjectOutputStream objOutput = new ObjectOutputStream(client.getOutputStream());
		//用同一输出流发送两个对象
		User user = new User("小明", 20);
		objOutput.writeObject(user);
		User user1 = new User("小红", 10);
		objOutput.writeObject(user1);
		client.shutdownOutput();
		client.close();
	}

	/// <summary>
/// 接收客户端发来的信息
/// </summary>
//	static void ServerRecMsg(Object socketClientPara)
//	{
//		Socket socketServer = socketClientPara as Socket;
//		//设置 5秒种超时
//		socketServer.setSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 5000);
//
//		int firstReceived = 0;
//		byte[] buffer = new byte[8192];
//		while (true)
//		{
//			try
//			{
//				//获取接收的数据,并存入内存缓冲区  返回一个字节数组的长度
//				if (socketServer != null)
//				{
//					firstReceived = socketServer.Receive(buffer);
//				}
//
//				//接受到的长度大于0 说明有信息或文件传来，有些客户端 发送0个字节 代表断开
//				if (firstReceived > 0)
//				{
//					byte[] result = buffer.Take(firstReceived).ToArray();
//					Console.WriteLine(BitConverter.ToString(result));
//				}
//				else
//				{
//					break;
//				}
//			}
//			catch (Exception ex)
//			{
//				Console.WriteLine(ex.Message);
//				socketServer.Close();//关闭socket连接
//				break;
//			}
//		}
//	}
}
